//
//  AppShareView.m
//  WisdomZhuHai
//
//  Created by yewei on 14/11/4.
//  Copyright (c) 2014年 wyd. All rights reserved.
//

#import "AppShareView.h"
#import "Common.h"
#import "UMSocial.h"
#import "AppDelegate.h"

@interface AppShareView()<UMSocialUIDelegate>

@end

@implementation AppShareView

-(id)initWithFrame:(CGRect)frame
{
    frame = [UIScreen mainScreen].bounds;
    self  = [super initWithFrame:frame];
    if(self)
    {
        self.backgroundColor = [UIColor clearColor];
        UIView *backView = [[UIView alloc] initWithFrame:frame];
        backView.backgroundColor = [UIColor blackColor];
        backView.alpha = 0.6;
        [self addSubview:backView];
        UIImage *erweimaImg = [UIImage imageNamed:@"erweima/erweimabanm.png"];
        UIView *erweimaView = [[UIView alloc] initWithFrame:CGRectMake((frame.size.width-erweimaImg.size.width)/2.0, (frame.size.height-erweimaImg.size.height)/2.0, erweimaImg.size.width, erweimaImg.size.height)];
        erweimaView.backgroundColor = [UIColor colorWithPatternImage:erweimaImg];
        [self addSubview:erweimaView];
        
        //分享按钮
        UIImage *img = [UIImage imageNamed:@"erweima/fenxiang1.png"];
        CGSize buttonSize = CGSizeMake(img.size.width + 20, img.size.height + 10);
        UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
//        shareBtn.backgroundColor = [UIColor redColor];
        button.frame = CGRectMake(20, erweimaView.bounds.size.height - buttonSize.height - 7, buttonSize.width, buttonSize.height);
        [button setBackgroundImage:[Common imageWithColor:[UIColor grayColor]] forState:UIControlStateHighlighted];
        [button setImage:img forState:UIControlStateNormal];
        [button addTarget:self action:@selector(shareClick) forControlEvents:UIControlEventTouchUpInside];
        [erweimaView addSubview:button];
        
        //关闭按钮
        img = [UIImage imageNamed:@"erweima/guanbi1.png"];
        buttonSize = CGSizeMake(img.size.width + 20, img.size.height + 10);
        button = [UIButton buttonWithType:UIButtonTypeCustom];
        button.frame = CGRectMake(erweimaView.bounds.size.width - buttonSize.width - 20, erweimaView.bounds.size.height - buttonSize.height - 7, buttonSize.width, buttonSize.height);
        [button setBackgroundImage:[Common imageWithColor:[UIColor grayColor]] forState:UIControlStateHighlighted];
        [button setImage:img forState:UIControlStateNormal];
        [button addTarget:self action:@selector(closeClisk) forControlEvents:UIControlEventTouchUpInside];
        [erweimaView addSubview:button];
        
    }
    return self;
}

-(void)shareClick
{
    [UMSocialSnsService presentSnsIconSheetView:[UIApplication sharedApplication].keyWindow.rootViewController
                                         appKey:nil
                                      shareText:self.string_share
                                     shareImage:[UIImage imageNamed:@"120.png"]
                                shareToSnsNames:[NSArray arrayWithObjects:UMShareToSina,UMShareToQQ,UMShareToSms,UMShareToWechatSession,UMShareToWechatTimeline,nil]
                                       delegate:self];
}

-(void)closeClisk
{
    [self removeFromSuperview];
}

-(BOOL)isDirectShareInIconActionSheet
{
    return YES;
}

-(void)didFinishGetUMSocialDataInViewController:(UMSocialResponseEntity *)response
{
    //根据`responseCode`得到发送结果,如果分享成功
    if(response.responseCode == UMSResponseCodeSuccess)
    {
        //得到分享到的微博平台名
        NSLog(@"%s || share to sns name is %@",__FUNCTION__, [[response.data allKeys] objectAtIndex:0]);
    }
}
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
